﻿using BCCommon;
using BCCommon.TMS.Driver;
using BCCommon.TMS.Order;
using BCCommon.TMS.Task;
using BCDto.Sim.Admin.AdminOperationRecord;
using BCCommon.TMS.RedPacket;
using BCDto.TMS.KanBan.AgentKanBan;
using BCDto.TMS.LearnTrain.LearnTrainStatistics;
using BCDto.TMS.MarketingCoupon.MarketingCouponStatistics;
using BCDto.TMS.RedPacket.RedPacketStatistics;
using BCService.TMS.KanBan.AgentKanBan;
using BCService.TMS.LearningTrain;
using BCService.TMS.MarketingCoupon.MarketingCouponStatistics;
using BCService.TMS.RedPacket.RedPacket;
using Microsoft.AspNetCore.Mvc;
using System;

namespace BCTMSRESTful.Controllers.Management.TMS.KanBan
{
    /// <summary>
    /// 代理商看板
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class AgentKanBanController : ManagementBaseController
    {
        private readonly IAgentKanBanService agentKanBanService;
        private readonly IPendingLearningVehicleService pendingLearningVehicleService;
        private readonly IRedPacketService redPacketService;
        private readonly IMarketingCouponStatisticsService marketingCouponStatisticsService;
        public AgentKanBanController(IAgentKanBanService agentKanBanService,
            IPendingLearningVehicleService pendingLearningVehicleService,
            IRedPacketService redPacketService,
            IMarketingCouponStatisticsService marketingCouponStatisticsService)
        {
            this.agentKanBanService = agentKanBanService;
            this.pendingLearningVehicleService = pendingLearningVehicleService;
            this.redPacketService = redPacketService;
            this.marketingCouponStatisticsService = marketingCouponStatisticsService;
        }

        #region 培训门户
        /// <summary>
        /// 司机培训人数统计
        /// </summary>
        /// <param name="datetime">时间</param>
        /// <param name="trainingSiteConfigId">培训点配置id</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(LearnTrainDto), 200)]
        public IActionResult LearnTrainCount(
            [FromQuery(Name = "datetime")] DateTime? datetime,
            [FromQuery(Name = "training_site_config_id")] long? trainingSiteConfigId)
        {
            if (Admin.AgentRecord == null)
            {
                throw new ArgumentException(" 用户认证失败,错误操作 ");
            }
            var result = this.pendingLearningVehicleService.GetLearningDriverCount(Admin.AgentRecord.AgentRecordId, datetime, trainingSiteConfigId);
            return this.Ok(result);
        }

        #endregion

        /// <summary>
        /// 获取司机/骑手累计信息
        /// </summary>
        /// <param name="driverRoleType">司机角色类型</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(DriverAnalysisDto), 200)]
        public IActionResult DriverAnalysis([FromQuery(Name = "driver_role_type")] DriverRoleType driverRoleType)
        {
            var result = this.agentKanBanService.GetDriverAnalysis(this.Admin, driverRoleType);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取订单累计信息
        /// </summary>
        /// <param name="orderStatus">订单状态</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(OrderAnalysisDto), 200)]
        public IActionResult OrderAnalysis([FromQuery(Name = "order_status")] OrderStatus orderStatus)
        {
            var result = this.agentKanBanService.GetOrderAnalysis(this.Admin, orderStatus);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取订单统计信息
        /// </summary>
        /// <param name="orderStatus">订单状态</param>
        /// <param name="completeTime">完成时间</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(OrderStatisticDto), 200)]
        public IActionResult OrderStatistic([FromQuery(Name = "order_status")] OrderStatus orderStatus,
            [FromQuery(Name = "complete_time")] DateTime? completeTime)
        {
            var result = this.agentKanBanService.GetOrderStatistic(this.Admin, orderStatus, completeTime);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取订单区域分析信息
        /// </summary>
        /// <param name="orderStatus">订单状态</param>
        /// <param name="completeTime">完成时间</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(OrderAreaAnalysisDto), 200)]
        public IActionResult OrderAreaAnalysis([FromQuery(Name = "order_status")] OrderStatus orderStatus,
            [FromQuery(Name = "complete_time")] DateTime? completeTime)
        {
            var result = this.agentKanBanService.GetOrderAreaAnalysis(this.Admin, orderStatus, completeTime);
            return this.Ok(result);
        }
        #region 优惠券统计
        /// <summary>
        /// 优惠券
        /// </summary>
        /// <param name="isCommonBusiness">是否通用</param>
        /// <param name="vehicleTransportBusinessConfigId">运输业务id</param>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(MarketingCouponStatisticsDto), 200)]
        public IActionResult MarketingCoupon([FromQuery(Name = "is_common_business")] bool? isCommonBusiness,
            [FromQuery(Name = "vehicle_transport_business_config_id")] long? vehicleTransportBusinessConfigId,
            [FromQuery(Name = "start_date")] DateTime? startDate,
            [FromQuery(Name = "end_date")] DateTime? endDate
            )
        {
            if (this.Admin.AgentRecord == null)
            {
                throw new ArgumentException(" 用户验证失败,错误操作! ");
            }
            var result = this.marketingCouponStatisticsService.GetMarketingCouponAgentStatistics(this.Admin, isCommonBusiness, vehicleTransportBusinessConfigId,
                startDate, endDate);
            return this.Ok(result);
        }
        #endregion

        #region 红包
        /// <summary>
        /// 红包
        /// </summary>
        /// <param name="grundlagenType">注册方式</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(RedPacketAgentStatisticsDto), 200)]
        public IActionResult RedPacket([FromQuery(Name = "grundlagen_type")] GrundlagenTypeEnum? grundlagenType)
        {
            if (this.Admin.AgentRecord == null)
            {
                throw new ArgumentException(" 用户验证失败,错误操作! ");
            }
            var result = this.redPacketService.GetRedPacketAgentStatistics(this.Admin, grundlagenType);
            return this.Ok(result);
        }
        #endregion
        /// <summary>
        /// 获取一组系统管理员操作记录信息。
        /// </summary>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="pageIndex">自 1 开始的页码编号。</param>
        /// <param name="pageSize">每页显示的数据条数。</param>
        /// <response code="200">获取一组系统管理员操作记录信息。</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<AdminOperationRecordDto>), 200)]
        public IActionResult Get(
            [FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "page_index")] int pageIndex = 1,
            [FromQuery(Name = "page_size")] int pageSize = 10)
        {
            return this.Ok(this.agentKanBanService.GetAdminOperationRecords(this.Admin, pageIndex, pageSize, start, end));
        }

        /// <summary>
        /// 获取司机动态信息
        /// </summary>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(DriverDynamicDto), 200)]
        public IActionResult DriverDynamic()
        {
            var result = this.agentKanBanService.GetDriverDynamic(this.Admin);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取待处理任务
        /// </summary>
        /// <response code="200">获取待处理任务。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PendingTasksDto), 200)]
        public IActionResult PendingTasks([FromQuery(Name = "task_type")] TaskTypeEnum taskType)
        {
            var result = this.agentKanBanService.GetPendingTasks(this.Admin, taskType);
            return this.Ok(result);
        }
    }
}
